﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace Tsanie.OsuDevice.Models {
    class Beatmap {
        public string MapID { get; set; }
        public string Title { get; set; }
        public string Artist { get; set; }
        public string Creator { get; set; }
        public string[] Versions { get; set; }
        public string Date { get; set; }
        public string Source { get; set; }
        public string[] Tags { get; set; }

        public DirectoryInfo SongDir { get; set; }

        public bool IsFullInfo {
            get {
                return this.MapID != null &&
                    this.Title != null &&
                    this.Artist != null &&
                    this.Creator != null &&
                    this.Source != null &&
                    this.Tags != null &&
                    this.Date != null;
            }
        }

        public override string ToString() {
            return MapID + '¥'
                + Title + '¥'
                + Artist + '¥'
                + Creator + '¥'
                + (Versions == null ? null : string.Join(",", Versions)) + '¥'
                + Source + '¥'
                + (Tags == null ? null : string.Join(",", Tags)) + '¥'
                + Date + '¥'
                + (SongDir == null ? "" : SongDir.FullName);
        }

        public static Beatmap Parse(string str) {
            string[] pars = str.Split(new char[] { '¥' }, StringSplitOptions.None);
            if (pars.Length != 9)
                return null;
            return new Beatmap() {
                MapID = pars[0],
                Title = pars[1],
                Artist = pars[2],
                Creator = pars[3],
                Versions = pars[4].Split(','),
                Source = pars[5],
                Tags = pars[6].Split(','),
                Date = pars[7],
                SongDir = (string.IsNullOrEmpty(pars[8]) ? null : new DirectoryInfo(pars[8]))
            };
        }
    }
}
